﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE80;
using EnvDTE;
using System.IO;

namespace DesignPatternToolkit.Wizard.Helpers
{
    public class DteHelper
    {
        private DTE _visualStudioEnv;

        public DteHelper(DTE visualStudioEnv)
        {
            _visualStudioEnv = visualStudioEnv;
        }

        public Project GetProjectRefByName(string projectName)
        {
            Project result = null;

            Solution solution = _visualStudioEnv.Solution;
            foreach (Project project in solution.Projects)
            {
                if (project.Name == projectName)
                {
                    result = project;
                    break;
                }
            }
            return result;
        }

        /// <summary>
        /// Adds a <see cref="FileInfo"/> object to the selected project.
        /// </summary>
        /// <param name="selectedProject"></param>
        /// <param name="selectedFile"></param>
        public void AddProjectItem(Project selectedProject, FileInfo selectedFile)
        {
            selectedProject.ProjectItems.AddFromFile(selectedFile.FullName);
        }
    }
}
